package com.flowerplus.store.api;

import android.support.annotation.NonNull;

import com.flowerplus.store.common.data.utils.JsonUtil;
import com.flowerplus.store.constant.Constant;
import com.flowerplus.store.constant.Methods;
import com.flowerplus.store.models.result.ResultBean;
import com.flowerplus.store.utils.Utils;

import java.util.HashMap;

import retrofit2.Retrofit;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by ems on 2017/2/27.
 */

public class ApiService {

    Retrofit retrofit;
    JsonUtil mJsonUtil;
    private final Api api;

    public ApiService(Retrofit retrofit, JsonUtil jsonUtil) {
        this.retrofit = retrofit;
        this.mJsonUtil = jsonUtil;
        api = retrofit.create(Api.class);
    }

    //获取基本的参数

    @NonNull
    public HashMap<String, String> getMap() {
        HashMap<String, String> map = new HashMap<>();
//        map.put("version", SystemUitl.getVersionName(App.getApp()));
//        map.put("operation_sys", "Android");
        return map;
    }

//    /**
//     * 登录
//     */
//    public Observable<ResultBean<User>> login(String naid, String phone, String psd) {
//        Map<String, Object> map = getMap();
//        map.put("na_id", naid);
//        map.put("mobile", phone);
//        map.put("password", psd);
//        String json = JsonUtil.getInstance().toJson(map);
//        return api.login(json)
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread());
//    }
    /**
     * 校验手机号码是否是新用户
     */
    public Observable<ResultBean> checkMobile(String mobile) {
        HashMap<String, String> map = getMap();
        map.put(Methods.METHOD, Methods.CHECKPASSWORD);
        map.put(Constant.MOBILE, mobile);
//        map.put(Constant.SIGN, Utils.getSign(map));
//        String json = JsonUtil.getInstance().toJson(map);
        return api.checkMobile( Methods.CHECKPASSWORD,mobile,Utils.getSign(map))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }

























}
